import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import path from 'node:path'
import dts from 'vite-plugin-dts'  // 生成ts声明文件

export default defineConfig(({command})=>{
    const isDev = command !== 'build'
    console.log("isDev=",isDev)
    return {
        plugins: [react(),
    dts({
        outDir:path.resolve(__dirname, 'dist'),
        include:['package/**/*.ts','package/**/*.tsx'],
        insertTypesEntry: true,
        rollupTypes: true,
    })
  ],
  root: isDev?path.resolve(__dirname, 'example'):undefined, // undefined表示默认根目录
  server: {
    port: 3000,
    open: true,
  },
  build: {
    outDir: path.resolve(__dirname, 'dist'),
    lib: {
        entry: path.resolve(__dirname, 'packages/index.ts'),
        name: 'ui',
        formats:['es','umd','cjs','iife'],
        fileName: (format) => `ui.${format}.js`
    },
    rollupOptions: {
      external: ['react', 'react-dom'],
      output: {
        globals: {
          react: 'React',
          'react-dom': 'ReactDOM',
        },
      },
    },
  },
    }
})

// export default defineConfig({
  
// })